home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_10_01 / cips1001.exe / DJET.C < prev    next >
Text File  |  1990-09-08  |  24KB  |  895 lines

  1.  
  2.  
  3.    /********************************************************
  4.    *
  5.    *   file d:\cips\djet.c
  6.    *
  7.    *   Functions: This file contains
  8.    *      end_graphics_mode
  9.    *      get_graphics_caption
  10.    *      print_bytes
  11.    *      print_graphics_image
  12.    *      print_original_200_row
  13.    *      select_300_dpi_resolution
  14.    *      select_full_graphics_mode
  15.    *      set_horizontal_offset
  16.    *      set_raster_width
  17.    *      start_raster_graphics
  18.    *
  19.    *   Purpose:
  20.    *      These functions print a 200x200 image using
  21.    *      dithering to an HP DeskJet or compatable (Laserjet).  
  22.    *      This uses an 8x8 matrix which gives 64 shades of 
  23.    *      gray.
  24.    *
  25.    *   External Calls:
  26.    *          rtiff.c - read_tiff_image
  27.    *           hist.c - zero_histogram
  28.    *                    calculate_histogram
  29.    *                    perform_histogram_equalization
  30.    *
  31.    *
  32.    *   Modifications:
  33.    *      January 1991 - created
  34.    *      25 August 1991 - modified for use in the 
  35.    *         C Image Processing System.
  36.    *
  37.     ┌─────┐   ┌─────┐
  38.     │     │   │     │   The function print_graphics_image
  39.     │     │   │     │   begins with 2 100x100 image arrays
  40.     │     │   │     │
  41.     │     │   │     │
  42.     └─────┘   └─────┘          
  43.               
  44.     ┌───────────────┐
  45.     │               │   It joins them into 
  46.     │               │   1 100x200 image array
  47.     │               │
  48.     │               │
  49.     └───────────────┘
  50.         
  51.     ┌───────────────┐
  52.     └───────────────┘
  53.     ┌───────────────┐
  54.     └───────────────┘ 
  55.            .            It loops and creates
  56.            .            100 200 element image arrays
  57.            .
  58.     ┌───────────────┐
  59.     └───────────────┘
  60.     
  61.     
  62.           The function print_original_200_row receives a 200 
  63.           element array
  64.     ┌┬──────────────────────────┬┐
  65.     └┴──────────────────────────┴┘
  66.  
  67.           This array is transformed into a 8x200 array of 
  68.           characters called 'row'
  69.     ┌───────── ... ■───────┐
  70.     ├───────── ... ■───────┤
  71.     ├───────── ... ■───────┤
  72.     ├───────── ... ■───────┤
  73.     ├───────── ... ■───────┤
  74.     ├───────── ... ■───────┤
  75.     ├───────── ... ■───────┤
  76.     ├───────── ... ■───────┤
  77.     └───────── ... ■───────┘
  78.  
  79.           Each column of this array is a 1x8 character array which 
  80.           is an 8-bit x 8-bit array
  81.     ╔══╗
  82.     ║  ║
  83.     ╚══╝
  84.           Each row of 'row' is passed to the funnction print_bytes 
  85.           for graphics printing 
  86.     
  87.     
  88.  
  89.  
  90.  
  91.  
  92.    ********************************************************/
  93.  
  94.  
  95. #include "d:\cips\cips.h"
  96.  
  97. #define ESCAPE 27
  98. #define FORMFEED  '\014'
  99.  
  100. short r[200];
  101.  
  102.  
  103.  
  104.       /*******************************************
  105.       *
  106.       *   The patterns array holds the rows to the
  107.       *   8x8 matrices used for printing 
  108.       *   shades of gray.
  109.       *
  110.       ********************************************/
  111.  
  112. char patterns[64][8] =
  113.    { {255, 255, 255, 255, 255, 255, 255, 255},
  114.      {255, 255, 255, 255, 255, 255, 255, 127},
  115.      {255, 255, 255, 255, 255, 255, 255,  63},
  116.      {255, 255, 255, 255, 255, 255, 255,  31},
  117.      {255, 255, 255, 255, 255, 255, 255,  15},
  118.      {255, 255, 255, 255, 255, 255, 255,   7},
  119.      {255, 255, 255, 255, 255, 255, 255,   3},
  120.      {255, 255, 255, 255, 255, 255, 255,   1},
  121.      {255, 255, 255, 255, 255, 255, 255,   0},
  122.      {255, 255, 255, 255, 255, 255, 127,   0},
  123.      {255, 255, 255, 255, 255, 255,  63,   0},
  124.      {255, 255, 255, 255, 255, 255,  31,   0},
  125.      {255, 255, 255, 255, 255, 255,  15,   0},
  126.      {255, 255, 255, 255, 255, 255,   7,   0},
  127.      {255, 255, 255, 255, 255, 255,   3,   0},
  128.      {255, 255, 255, 255, 255, 255,   1,   0},
  129.      {255, 255, 255, 255, 255, 255,   0,   0},
  130.      {255, 255, 255, 255, 255, 127,   0,   0},
  131.      {255, 255, 255, 255, 255,  63,   0,   0},
  132.      {255, 255, 255, 255, 255,  31,   0,   0},
  133.      {255, 255, 255, 255, 255,  15,   0,   0},
  134.      {255, 255, 255, 255, 255,   7,   0,   0},
  135.      {255, 255, 255, 255, 255,   3,   0,   0},
  136.      {255, 255, 255, 255, 255,   1,   0,   0},
  137.      {255, 255, 255, 255, 255,   0,   0,   0},
  138.      {255, 255, 255, 255, 127,   0,   0,   0},
  139.      {255, 255, 255, 255,  63,   0,   0,   0},
  140.      {255, 255, 255, 255,  31,   0,   0,   0},
  141.      {255, 255, 255, 255,  15,   0,   0,   0},
  142.      {255, 255, 255, 255,   7,   0,   0,   0},
  143.      {255, 255, 255, 255,   3,   0,   0,   0},
  144.      {255, 255, 255, 255,   1,   0,   0,   0},
  145.      {255, 255, 255, 255,   0,   0,   0,   0},
  146.      {255, 255, 255, 127,   0,   0,   0,   0},
  147.      {255, 255, 255,  63,   0,   0,   0,   0},
  148.      {255, 255, 255,  31,   0,   0,   0,   0},
  149.      {255, 255, 255,  15,   0,   0,   0,   0},
  150.      {255, 255, 255,   7,   0,   0,   0,   0},
  151.      {255, 255, 255,   3,   0,   0,   0,   0},
  152.      {255, 255, 255,   1,   0,   0,   0,   0},
  153.      {255, 255, 255,   0,   0,   0,   0,   0},
  154.      {255, 255, 127,   0,   0,   0,   0,   0},
  155.      {255, 255,  63,   0,   0,   0,   0,   0},
  156.      {255, 255,  31,   0,   0,   0,   0,   0},
  157.      {255, 255,  15,   0,   0,   0,   0,   0},
  158.      {255, 255,   7,   0,   0,   0,   0,   0},
  159.      {255, 255,   3,   0,   0,   0,   0,   0},
  160.      {255, 255,   1,   0,   0,   0,   0,   0},
  161.      {255, 255,   0,   0,   0,   0,   0,   0},
  162.      {255, 127,   0,   0,   0,   0,   0,   0},
  163.      {255,  63,   0,   0,   0,   0,   0,   0},
  164.      {255,  31,   0,   0,   0,   0,   0,   0},
  165.      {255,  15,   0,   0,   0,   0,   0,   0},
  166.      {255,   7,   0,   0,   0,   0,   0,   0},
  167.      {255,   3,   0,   0,   0,   0,   0,   0},
  168.      {255,   1,   0,   0,   0,   0,   0,   0},
  169.      {255,   0,   0,   0,   0,   0,   0,   0},
  170.      {127,   0,   0,   0,   0,   0,   0,   0},
  171.      { 63,   0,   0,   0,   0,   0,   0,   0},
  172.      { 31,   0,   0,   0,   0,   0,   0,   0},
  173.      { 15,   0,   0,   0,   0,   0,   0,   0},
  174.      {  7,   0,   0,   0,   0,   0,   0,   0},
  175.      {  3,   0,   0,   0,   0,   0,   0,   0},
  176.      {  1,   0,   0,   0,   0,   0,   0,   0}};
  177.  
  178.  
  179.  
  180.  
  181.  
  182. print_graphics_image(image1, image2, image_name,
  183.                      il, ie, ll, le, image_colors,
  184.                      invert, caption, show_hist,
  185.                      color_transform)
  186.    char  caption[], image_name[], color_transform[];
  187.    int   image_colors, invert,
  188.          il, ie, ll, le, show_hist;
  189.    short image1[ROWS][COLS], image2[ROWS][COLS];
  190. {
  191.    char c[80],
  192.         page[80];
  193.  
  194.    FILE *printer;
  195.  
  196.    int  i,
  197.         j;
  198.  
  199.    unsigned long histogram[256], final_hist[256];
  200.    printer = fopen("prn", "w");
  201.  
  202.  
  203.       /**********************************************
  204.       *
  205.       *   Print a few blank lines on the page.
  206.       *
  207.       ***********************************************/
  208.  
  209.    strcpy(page, "                             ");
  210.    my_fwriteln(printer, page);
  211.    my_fwriteln(printer, page);
  212.  
  213.  
  214.       /*****************************************************
  215.       *
  216.       *   Read in two image arrays.
  217.       *
  218.       ******************************************************/
  219.  
  220.    printf("\nReading image");
  221.    read_tiff_image(image_name, image1, il, ie, ll, le);
  222.  
  223.  
  224.    printf("\nReading image");
  225.    read_tiff_image(image_name, image2, il, ie+100, ll, le+100);
  226.  
  227.  
  228.       /*****************************************************
  229.       *
  230.       *   If show_hist is 1 OR do hist equalization
  231.       *   then zero the histogram and
  232.       *   calculate it for the two image arrays.
  233.       *
  234.       ******************************************************/
  235.  
  236.    if( (show_hist == 1)  ||
  237.        (color_transform[0] == 'H')){
  238.       zero_histogram(histogram);
  239.       zero_histogram(final_hist);
  240.       printf("\nDJET> Calculating histograms");
  241.       calculate_histogram(image1, histogram);
  242.       calculate_histogram(image2, histogram);
  243.    }
  244.  
  245.         /**************************************************
  246.         *
  247.         *   Alter the images to 64 gray shades.
  248.         *   Either do it with straight multiply
  249.         *   and divide or use hist equalization.
  250.         *
  251.         *   If using hist equalization then you must
  252.         *   also read and calculate the hist for
  253.